//
//  TestViewModel.swift
//  LiveShow
//
//  Created by dai zhong on 2017/5/10.
//  Copyright © 2017年 company.cn. All rights reserved.
//

import UIKit

class TestViewModel: NSObject , NetworkProtocol{

    var requestType = RequestType.get
    var urlString :String = "http://qf.56.com/pay/v4/giftList.ios"
    var parameters:[String :Any]? = ["type" : 0, "page" : 1, "rows" : 150]
    
    lazy var packages : [GIftPackage] = [GIftPackage]()
    
    
}

extension TestViewModel{

    func parseData(_ result :Any){
    
        guard let resultDict = result as? [String :Any] else { return }
        
        guard let typesResultDict = resultDict["message"] as? [String :Any] else { return }
        
        for i in 0..<typesResultDict.count {
            
            guard let typeDict = typesResultDict["type\(i+1)"] as? [String :Any] else { return }
            self.packages.append(GIftPackage(dict: typeDict))
            
        }
        
        self.packages = self.packages.filter({ $0.t > 0 }).sorted(by: { $0.t > $1.t})
        
        print(result)
    }
}
